package com.lemon.smartsafetynew.ui.adapter.notice;

import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecycleChildItemClickListener;
import com.lemon.smartsafetynew.entity.notice.NoticeInfoVo;
import java.util.List;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/7/11.
 */

public class NoticeListAdapter extends LemonRcvAdapter<NoticeInfoVo> {

    private RecycleChildItemClickListener<NoticeInfoVo> mChildListener;
    private int type;

    public NoticeListAdapter(List<NoticeInfoVo> data, RecycleChildItemClickListener<NoticeInfoVo> childListener, int type) {
        super(data);
        this.mChildListener = childListener;
        this.type = type;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new NoticeItem();
    }

    public class NoticeItem implements AdapterItem<NoticeInfoVo> {

        // ======= view =======
        TextView noticeTitleTv;

        TextView noticeDateTv;

        ImageView noticeHasReadIv;

        TextView noticeContentSummaryTv;

        ImageView lstopImageBt;

        TextView noticeMoreTv;

        RelativeLayout noticeLayout;

        TextView noticeTimestampTv;

        private NoticeInfoVo mData;
        private int mPosition;

        @Override
        public int getLayoutResId() {
            return R.layout.item_notice_info_list;
        }

        @Override
        public void bindViews(View root) {

            noticeTitleTv = (TextView)root.findViewById(R.id.notice_title_tv);
            noticeDateTv = (TextView)root.findViewById(R.id.notice_date_tv);
            noticeHasReadIv = (ImageView)root.findViewById(R.id.notice_hasRead_iv);
            noticeContentSummaryTv = (TextView)root.findViewById(R.id.notice_content_summary_tv);
            lstopImageBt = (ImageView)root.findViewById(R.id.lstop_image_bt);
            noticeMoreTv = (TextView)root.findViewById(R.id.notice_more_tv);
            noticeLayout = (RelativeLayout)root.findViewById(R.id.notice_view_layout);
            noticeTimestampTv = (TextView)root.findViewById(R.id.notice_timestamp_tv);

        }

        @Override
        public void setViews() {

            noticeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mChildListener != null) {
                        mChildListener.onItemClick(mData, mPosition);
                    }
                }
            });

            lstopImageBt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //TODO
                    if(mChildListener != null) {
                        mChildListener.onChildItemClick(mData, mPosition);
                    }
                }
            });
        }

        @Override
        public void handleData(NoticeInfoVo data, int position) {
            Log.e("yxy", "handleData " + position);
            mData = data;
            mPosition = position;

            switch (type) {
                case 0:
                    lstopImageBt.setVisibility(View.GONE);
                    noticeHasReadIv.setVisibility(View.GONE);
                    break;
                case 1:
                    //TODO
                    break;
                case 2:
                    //TODO
                    break;
                default:
                    break;
            }

            noticeTitleTv.setText(data.getTitle());
//            tvItemTitle.setText(StringUtils.nullValue(data.getTitle()));
//            if (StringUtils.getBoolean(data.getHasRead())) {
//                tvStatus.setText(StringUtils.getStatusString("已读", StringUtils.ColorStatus.STATUS_GREEN));
//            } else {
//                tvStatus.setText(StringUtils.getStatusString("未读", StringUtils.ColorStatus.STATUS_RED));
//            }
//            tvUnit.setText(StringUtils.nullValue(data.getGovName()));
//            tvDate.setText(StringUtils.friendly_time(data.getRecordDate()));

        }

    }
}